package com.order.manager.controller;

import com.order.manager.Model.TeamUser;
import com.order.manager.service.TeamUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/teamuser")
public class TeamUserController {

    @Autowired
    private TeamUserService teamUserService;

    // 新增团队成员
    @PostMapping("/add")
    public boolean addTeamUser(@RequestBody TeamUser teamUser) {
        return teamUserService.save(teamUser);
    }

    // 根据ID删除团队成员
    @DeleteMapping("/delete/{id}")
    public boolean deleteTeamUser(@PathVariable Integer id) {
        return teamUserService.removeById(id);
    }

    // 修改团队成员信息
    @PutMapping("/update/{id}")
    public boolean updateTeamUser(@PathVariable Integer id, @RequestBody TeamUser teamUser) {
        teamUser.setStuId(id);
        return teamUserService.updateById(teamUser);
    }

    // 根据ID查询团队成员
    @GetMapping("/get/{id}")
    public TeamUser getTeamUser(@PathVariable Integer id) {
        return teamUserService.getById(id);
    }

    // 查询所有团队成员
    @GetMapping("/list")
    public List<TeamUser> listTeamUsers() {
        return teamUserService.list();
    }
}